package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsBrandMapper;
import com.qf.pojo.DtsBrand;
import com.qf.service.DtsBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @version 1.0
 * @auther Administrator
 * @date 2023/2/24 17:38
 */
@Service
public class DtsBrandServiceImpl implements DtsBrandService {

    @Autowired
    private DtsBrandMapper dtsBrandMapper;

    /**
     * 品牌制造商列表
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @param name
     * @return
     */
    @Override
    public IPage<DtsBrand> findListByQuery(Integer page, Integer limit, String sort, String order,Integer id, String name) {
        return dtsBrandMapper.selectPage(new Page<DtsBrand>(page, limit)
                , new QueryWrapper<DtsBrand>()
                        .like(!StringUtils.isEmpty(name), "name", name)
                        .eq(!StringUtils.isEmpty(id), "id", id)
                        .orderBy(!StringUtils.isEmpty(sort), "ASC".equalsIgnoreCase(order), sort)
        );
    }

    /**
     * 添加
     * @param dtsBrand
     * @return
     */
    @Override
    public DtsBrand create(DtsBrand dtsBrand) {
        dtsBrandMapper.insert(dtsBrand);
        return dtsBrand;
    }

    /**
     * 更新
     * @param dtsBrand
     * @return
     */
    @Override
    public DtsBrand update(DtsBrand dtsBrand) {
        dtsBrandMapper.updateById(dtsBrand);
        return dtsBrand;
    }

    /**
     * 删除
     * @param dtsBrand
     * @return
     */
    @Override
    public DtsBrand delete(DtsBrand dtsBrand) {
        dtsBrandMapper.deleteById(dtsBrand);
        return dtsBrand;
    }

    @Override
    public List<DtsBrand> findIdByAdminId(Integer id) {
        return dtsBrandMapper.selectList(new QueryWrapper<DtsBrand>().
                select("id").eq(id!=null,"admin_id",id));
    }

    @Override
    public List<DtsBrand> findBrandByAdminId(Integer id) {
        return dtsBrandMapper.selectList(new QueryWrapper<DtsBrand>().eq(id!=null,"admin_id",id));
    }


}
